﻿using System;
using System.Linq;
using System.Xml.Serialization;

namespace Torrenter.Common.Objects
{
    [Serializable]
    public class Torrent
    {
        #region public properties

        public string DownloadLocation { get; set; }

        public string LocalPath { get; set; }

        public string Name { get; set; }

        public EpisodeDefinition EpisodeDefinition { get; set; }

        [XmlIgnore]
        public string FileName
        {
            get { return DownloadLocation.Split('\\').Last(); }
        }

        [XmlIgnore]
        public bool WasFound
        {
            get { return !string.IsNullOrWhiteSpace(DownloadLocation); }
        }

        #endregion // public properties
        

        public static Torrent Generate(string showName,int seasonNumber,int episodeNumber)
        {
            return new Torrent()
            {
                Name = showName,
                EpisodeDefinition = new EpisodeDefinition(showName, seasonNumber, episodeNumber)
            };
        }

        public override string ToString()
        {
            return string.Format("Season: {0} Ep: {1} Show: {2}", EpisodeDefinition.SeasonNumber,
                                 EpisodeDefinition.EpisodeNumnber, Name);
        }
    }
}
